package cn.getech.data.metadata.controller.permision;

import cn.getech.data.intelligence.common.utils.PageUtils;
import cn.getech.data.intelligence.common.utils.R;
import cn.getech.data.metadata.entity.permission.CollectionTablePermissionExt;
import cn.getech.data.metadata.service.CollectionTableInfoService;
import cn.getech.system.center.annotation.SysLog;
import cn.getech.system.center.constant.OperationModulesEnum;
import cn.getech.system.center.constant.OperationTypeEnum;
import cn.getech.system.center.constant.module.ModuleEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @description: 权限管理
 * @author: wangzhaowen：kiss
 * @create: 2020/9/30 11:00
 * @version: 2020/9/30
 **/
@Slf4j
@Api(value="任务日志",tags={"任务日志"})
@RestController
@RequestMapping("md/table")
public class CollectionPermissionController {
    @Autowired
    private CollectionTableInfoService collectionTableInfoService;

    /**
     * 基础平台权限查询
     */
    @ApiOperation("获取数据表信息列表根据角色")
    @GetMapping("/listByRole")  // /data-metadata/md/table/listByRole
    @ResponseBody
    public R listByRole(@RequestParam Map<String, Object> params) {
        PageUtils<CollectionTablePermissionExt> page = collectionTableInfoService.listPageByRole(params);
        return R.okWithPage(page);
    }

    /**
     * 获取数据表信息列表创建人列表
     */
    @ApiOperation("获取数据表信息列表创建人列表")
    @GetMapping("/dataServiceUserList")
    @ResponseBody
    public R listUserList() {
        return R.okWithData(collectionTableInfoService.listUserList());
    }

    @ApiOperation(value = "保存元数据权限")
    @PostMapping("/savePermission")// /data-metadata/md/table/savePermission
    @ResponseBody
    @SysLog(value = "外部源表授权", type = OperationTypeEnum.APPROVECODE, modulesType = OperationModulesEnum.SYSMODECODE, platformModuleType = ModuleEnum.AUTH_MANAGER_MODULE_CODE)
    public R savePermission(@RequestBody List<CollectionTablePermissionExt> permissionList) {
        collectionTableInfoService.savePermission(permissionList);
        return R.ok();
    }
}
